﻿/// <reference path="../MicrosoftAjax.Debug.js" />

Type.registerNamespace('ExtJSExtender.Controls');

ExtJSExtender.Controls.NumberFieldExtenderBehavior = function (element) {
    ExtJSExtender.Controls.NumberFieldExtenderBehavior.initializeBase(this, [element]);
}

ExtJSExtender.Controls.NumberFieldExtenderBehavior.prototype = {
    _ExtControl: null,
    _TriggerPostBackEvents: null,
    initialize: function () {
        ExtJSExtender.Controls.NumberFieldExtenderBehavior.callBaseMethod(this, 'initialize');
        var id = this.get_element().id;
        var self = this;
        var cfg = {
            renderTo: id,
            disabled: !self.get_Enabled(),
            border: this.get_Border(),
            allowBlank: this.get_AllowBlank(),
            allowDecimals: this.get_AllowDecimals(),
            decimalPrecision: this.get_DecimalPrecision(),
            decimalSeparator: this.get_DecimalSeparator(),
            hideTrigger: this.get_HideTrigger(),
            keyNavEnabled: this.get_KeyNavEnabled(),
            mouseWheelEnabled: this.get_MouseWheelEnabled(),
            step: this.get_Step(),
            listeners: {
                'change': Function.createDelegate(self, self.raiseChange)
            }
        };
        if (this.get_Height()) cfg.height = this.get_Height();
        if (this.get_Width()) cfg.width = this.get_Width();
        if (this.get_Value()) cfg.value = this.get_Value();
        if (this.get_MaxValue()) cfg.maxValue = this.get_MaxValue();
        if (this.get_MinValue()) cfg.minValue = this.get_MinValue();

        //绘制控件
        Ext.onReady(function () {
            self._ExtControl = Ext.create('Ext.form.NumberField', cfg);
        }, this);
    },
    dispose: function () {
        ExtJSExtender.Controls.NumberFieldExtenderBehavior.callBaseMethod(this, 'dispose');
    },
    get_AutoPostBack: function () {
        return this._AutoPostBack;
    },
    set_AutoPostBack: function (value) {
        this._AutoPostBack = value;
    },
    get_AllowBlank: function () {
        return this._AllowBlank;
    },
    set_AllowBlank: function (value) {
        this._AllowBlank = value;
    },
    get_AllowDecimals: function () {
        return this._AllowDecimals;
    },
    set_AllowDecimals: function (value) {
        this._AllowDecimals = value;
    },
    get_DecimalPrecision: function () {
        return this._DecimalPrecision;
    },
    set_DecimalPrecision: function (value) {
        this._DecimalPrecision = value;
    },
    get_DecimalSeparator: function () {
        return this._DecimalSeparator;
    },
    set_DecimalSeparator: function (value) {
        this._DecimalSeparator = value;
    },
    get_HideTrigger: function () {
        return this._HideTrigger;
    },
    set_HideTrigger: function (value) {
        this._HideTrigger = value;
    },
    get_KeyNavEnabled: function () {
        return this._KeyNavEnabled;
    },
    set_KeyNavEnabled: function (value) {
        this._KeyNavEnabled = value;
    },
    get_MouseWheelEnabled: function () {
        return this._MouseWheelEnabled;
    },
    set_MouseWheelEnabled: function (value) {
        this._MouseWheelEnabled = value;
    },
    get_Step: function () {
        return this._Step;
    },
    set_Step: function (value) {
        this._Step = value;
    },
    get_Value: function () {
        return this._Value;
    },
    set_Value: function (value) {
        this._Value = value;
    },
    get_MaxValue: function () {
        return this._MaxValue;
    },
    set_MaxValue: function (value) {
        this._MaxValue = value;
    },
    get_MinValue: function () {
        return this._MinValue;
    },
    set_MinValue: function (value) {
        this._MinValue = value;
    },

    get_Enabled: function () {
        return this._Enabled;
    },
    set_Enabled: function (value) {
        this._Enabled = value;
    },
    get_Width: function () {
        return this._Width;
    },
    set_Width: function (value) {
        this._Width = value;
    },
    get_Height: function () {
        return this._Height;
    },
    set_Height: function (value) {
        this._Height = value;
    },
    get_Border: function () {
        return this._Border;
    },
    set_Border: function (value) {
        this._Border = value;
    },
    get_UniqueID: function () {
        return this._UniqueID;
    },
    set_UniqueID: function (value) {
        this._UniqueID = value;
    },
    get_ValueTextHiddenField: function () {
        return this._ValueTextHiddenField;
    },
    set_ValueTextHiddenField: function (value) {
        this._ValueTextHiddenField = value;
    },
    storeValue: function () {
        var self = this;
        //保存数据到隐藏域
        document.getElementById(self.get_ValueTextHiddenField()).value = self._ExtControl.getRawValue();
    },
    invoke: function (args, onComplete$delegate, context, onError$delegate, async) {
        var callbackId = this.get_UniqueID();
        if (this._AutoPostBack) {
            __doPostBack(callbackId, args);
        }
        else {
            //WebForm_DoCallback(callbackId, args, onComplete$delegate, context, onError$delegate, async);
        }
    },
    raiseChange: function (NumberField, newValue, opts) {
        this.storeValue();
    }
}

ExtJSExtender.Controls.NumberFieldExtenderBehavior.registerClass('ExtJSExtender.Controls.NumberFieldExtenderBehavior', Sys.UI.Control);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();